<?php
namespace App\Controller;
class ShopController extends HomeController {

    //商城首页
    public function index(){
        $uid=_param('uid','请登录');

        //首页banner
        $banner_where['typeid']=42;
        $banner_field='id,name,sort,status';
        $banner=M('ad')->where($banner_where)->field($banner_field)->select();
        if($banner){
            foreach ($banner as $k => $v){
                $banner[$k]['img_url']=picture($v['icon']);
            }
            $arr['banner']=$banner;
        }else{
            $arr['banner']=[];
        }

        //优质商家
        $hq_where['hq_shop']=2;
        $hq_where['status']=1;
        $hq_field='id,name,sort,status';
        $hq_shop=M('shop')->where($hq_field)->select();
        if($hq_shop){
            foreach ($hq_shop as $k=>$v){
                $hq_shop[$k]['img']=picture($v['shop_logo']);
            }
            $arr['hq_shop']=$hq_shop;
        }else{
            $arr['hq_shop']=[];
        }

        //推荐列表
        $page=I('page');
        if(empty($page) || $page<0){$page=1;}else{$page=$page;}
        $pagesize=10;
        $offset=$pagesize*($page-1);
        $goods_where['status']=1;
        $goods_field='id,goods_name,create_time,status,sales_volume,goods_img,price_type,goods_price,goods_tel';
        $goods_order='create_time desc';
        $goods=M('goods')->where($goods_where)->field($goods_field)->order($goods_order)->limit("$offset,$pagesize")->select();
        if($goods){
            foreach ($goods as $k=>$v){
                $imgs=explode(',',$v['goods_img']);
                $goods[$k]['goods_img']=picture($imgs[0]);
                if($v['price_type']==2){
                    $goods[$k]['goods_price']='面议';
                }
            }
            $arr['goods']=$goods;
        }else{
            $arr['goods']=[];
        }
        _success('商城首页',$arr);
    }

}